package com.dnake.panel;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Point;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.SurfaceView;
import android.widget.ImageView;

import com.dnake.Constant;
import com.dnake.service.GtPushService;
import com.dnake.service.GtReceiveService;
import com.dnake.utils.NetUtil;
import com.dnake.v700.dmsg;
import com.dnake.v700.dxml;
import com.igexin.sdk.PushManager;
import com.wx.android.common.util.SharedPreferencesUtils;

import butterknife.Bind;


/**
 * Created by haoyuliu on 2017/2/9.
 */

public class HomeActivity extends BaseActivity {
    @Bind(R.id.iv_splash_picture)
    ImageView ivSplashPicture;
    @Bind(R.id.local_surface)
    SurfaceView localSurface;
    @Override
    protected int getLayoutResId() {
        return R.layout.activity_splash;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        Point point = new Point();
        getWindowManager().getDefaultDisplay().getSize(point);
        if (SharedPreferencesUtils.getInt(Constant.SP_DELAY_TIME) <= 0) {
            SharedPreferencesUtils.put(Constant.SP_DELAY_TIME, 3);
        }
        if (SharedPreferencesUtils.getInt(Constant.SP_APP_TYPE) < 0) {
            SharedPreferencesUtils.put(Constant.SP_APP_TYPE, 0);
        }
        if (SharedPreferencesUtils.getInt(Constant.SP_FACE_SCORE)<=50){
            SharedPreferencesUtils.put(Constant.SP_FACE_SCORE,71);
        }
        if (SharedPreferencesUtils.getInt(Constant.SP_FACE_PAPERS_SCORE)<=30){
            SharedPreferencesUtils.put(Constant.SP_FACE_PAPERS_SCORE,51);
        }
        //初始化音频管理器
//        AudioManager mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
//        mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC), AudioManager.FLAG_PLAY_SOUND);
//        SoundPlayUtils.init(this);
        dmsg req = new dmsg();
        dxml p = new dxml();
        req.to("/settings/lan/query", null);
        p.parse(req.mBody);
        int mDhcp = p.getInt("/params/dhcp", 0);
        if (mDhcp==0){
            NetUtil.setNetwork();
        }
        PushManager.getInstance().initialize(this.getApplicationContext(), GtPushService.class);
        PushManager.getInstance().registerPushIntentService(this.getApplicationContext(), GtReceiveService.class);
        mHandler.sendEmptyMessageDelayed(100, 1000);
    }




    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 100:
                    startActivity(new Intent(HomeActivity.this, MainActivity.class));
                    finish();
                    break;
            }
        }
    };


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
